package com.penghk.hangzhouhouseprice.handler;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

@Component
public class MailSendHandler {

    private static final String hangzhouPrice = "杭州房价";

    @Value("${mail.username}")
    private String fromUser;


    @Autowired
    JavaMailSender javaMailSender;

    @Autowired
    SimpleMailMessage simpleMailMessage;

    public void sendMsg(String msg , String toUser) {
        simpleMailMessage.setFrom(fromUser);
        simpleMailMessage.setTo(toUser);
        simpleMailMessage.setSubject(hangzhouPrice);
        simpleMailMessage.setText(msg);
        javaMailSender.send(simpleMailMessage);
    }

}
